
public class LocalArrTime implements Comparable<LocalArrTime>{
	private int d,M,y,h,m;
	private double s;
	public LocalArrTime(int day,int month,int year,int hour, int minute,double seconds){
		d = day;
		M = month;
		y = year;
		h = hour;
		m = minute;
		s = seconds;
	}
	public LocalArrTime(int day, int month, int year){
		this(day,month,year,0,0,0);
	}
	public  LocalArrTime(LocalArrTime timeB){
		this(timeB.getDay(),timeB.getMonth(),timeB.getYear(),timeB.getHour(),timeB.getMinute(),timeB.getSecond());
	}
	/**
	 * 
	 * @param dateTime in dd/mm/yyyy hh:mm:ss.s AM(/PM) format
	 */
	public LocalArrTime(String dateTime){
		String stringParts[] = dateTime.split(" ");
		String dMY[] = stringParts[0].split("/");
		d = Integer.parseInt(dMY[0]);
		M = Integer.parseInt(dMY[1]);
		y = Integer.parseInt(dMY[2]);
		if(stringParts.length>1){
			String hms[] = stringParts[1].split(":");		
			if(stringParts[2].compareTo("AM")==0){
				h = Integer.parseInt(hms[0]);
			}else{
				h = Integer.parseInt(hms[0])+12;
			}
			m = Integer.parseInt(hms[1]);
			s = Double.parseDouble(hms[2]);
		}else{
			h = 0;
			m = 0;
			s = 0.0;
		}
	}
	/**
	 * return time difference in seconds
	 */
	public int compareTo(LocalArrTime timeB) {
		//the month calculation is not accurate
		int diffY, diffMonth,diffD,diffH,diffmin;
		double diffsec = s-timeB.getSecond();
		diffY = y-timeB.getYear();
		diffMonth = M-timeB.getMonth();
		diffD = d-timeB.getDay();
		diffH = h-timeB.getHour();
		diffmin = m-timeB.getMinute();
		return (int) (((((diffY*365.25+diffMonth*30)+diffD)*24+diffH)*60+diffmin)*60+diffsec);
	}
	
	public int getYear() {
		return y;
	}
	public int getMonth() {
		return M;
	}
	public int getHour() {
		return h;
	}
	private int getMinute() {
		return m;
	}
	private double getSecond() {
		return s;
	}
	public int getDay(){
		return d;
	}
	/**
	 * add time to the current time
	 * @param seconds
	 */
	public void addTime(double seconds){
		double time2Add = seconds;
		double days, hours, minutes;
		double temps,tempm,temph;
		double mCarry,hCarry,dCarry;
		days = Math.floor(time2Add/(3600*24));
		time2Add = time2Add-(3600*24)*days;
		hours = Math.floor(time2Add/(3600));
		time2Add = time2Add- 3600*hours;
		minutes = Math.floor(time2Add/60);
		time2Add = time2Add-60*minutes;
		seconds = time2Add;
		temps = s+seconds;
		s = (int) (temps)%60;
		mCarry = (int) Math.floor(temps/60);
		tempm = m+minutes+mCarry;
		m = (int) (tempm)%60;
		hCarry = Math.floor(tempm/60);
		temph = h+hours+hCarry;
		h = (int) (temph)%24;
		dCarry = Math.floor(temph/24);
		d = (int) (d+days+dCarry);
		
		
		
		
	}
	/**
	 * a copy of compateTo() method but instead return a double
	 * @param timeB
	 * @return
	 */
	public double timeDiff(LocalArrTime timeB){
		int diffY, diffMonth,diffD,diffH,diffmin;
		double diffsec = s-timeB.getSecond();
		diffY = y-timeB.getYear();
		diffMonth = M-timeB.getMonth();
		diffD = d-timeB.getDay();
		diffH = h-timeB.getHour();
		diffmin = m-timeB.getMinute();
		return  (((((diffY*365.25+diffMonth*30)+diffD)*24+diffH)*60+diffmin)*60+diffsec);
	}
	public String toString(){
		return (Integer.toString(d)+"/"+Integer.toString(M)+"/"+Integer.toString(y)+" "+Integer.toString(h)+":"+
	Integer.toString(m)+":"+Double.toString(s));
	}
	
	public boolean isFromSameFlight(LocalArrTime timeB){
		boolean returnValue;
		if(timeB.getDay() == d && timeB.getMonth() == M && timeB.getYear() == y && Math.abs(timeB.getHour()-h)<3){
			returnValue = true;
		}else{
			returnValue = false;
		}
		return returnValue;
	}
}
